home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Tools / Mac / FWPreBuild < prev    next >
Encoding:
Text File  |  1996-04-25  |  6.4 KB  |  289 lines  |  [TEXT/MPS ]

  1. #========================================================================================
  2. #
  3. #    File:                FWPreBuild
  4. #    Release Version:    $ ODF 1 $
  5. #
  6. #    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. #
  8. #========================================================================================
  9.  
  10. # This script is used for "pre-building" ODF targets.
  11. #
  12. # By "pre-building" we refer to the process of generating SOM
  13. # ≈.xh files from their ≈.idl counterparts as well as generating
  14. # ≈.rsrc resource file from ≈.r and ≈.fr sources.  This is normally
  15. # done only once and need not be done again unless an ≈.idl, ≈.fr,
  16. # ≈.r file is revised.
  17.  
  18. Set TraceFailures 1
  19. Export TraceFailures
  20.  
  21. # Save our current directory so we can restore it later.
  22.  
  23. Set StartDir "``Directory -q``"
  24.  
  25. # Initialize script vars
  26.  
  27. Set DefRul "{FWToolsDir}FWPreBuild.rul"
  28. Set TempFile "{TempFolder}{0}.out"
  29. Set somDir "Include"
  30. Set resDir "Other"
  31. Set Progress 0
  32. Set Dump 0
  33. Set NoCleanup 0
  34.  
  35. Set Usage "Usage: {0} [-som somDirectory] [-res resDirectory] [-p] [-dump] Target1 Target2..."
  36.  
  37. # Parse for flags and remove them from param list as we go
  38.  
  39. Loop
  40.     If "{1}" =~ /-som/
  41.         Set somDir "{2}"
  42.         Shift
  43.     Else If "{1}" =~ /-res/
  44.         Set resDir "{2}"
  45.         Shift
  46.     Else If "{1}" =~ /-help/
  47.         Echo "{Usage}"
  48.         Echo "∂t-som∂t--> location of the SOM idl files within target directory (default ∂'{somDir}∂')."
  49.         Echo "∂t-res∂t--> location of the resource files within target directory (default ∂'{resDir}∂')."
  50.         Echo "∂t-p  ∂t--> give progress info as script executes."
  51.         Echo "∂t-dump∂t--> create the MakeFile but don't execute it."
  52.         Exit 0
  53.     Else If "{1}" =~ /-p/
  54.         Set Progress 1
  55.     Else If "{1}" =~ /-dump/
  56.         Set Dump 1
  57.         Set NoCleanup 1
  58.     Else
  59.         Break
  60.     End
  61.     Shift
  62. End
  63.  
  64. # If no remaining parameters then we print a usage string and exit
  65.  
  66. If {#} == 0
  67.     Echo "{Usage}"
  68.     Echo "∂t-som∂t--> location of the SOM idl files within target directory (default ∂'{somDir}∂')."
  69.     Echo "∂t-res∂t--> location of the resource files within target directory (default ∂'{resDir}∂')."
  70.     Echo "∂t-p  ∂t--> give progress info as script executes."
  71.     Echo "∂t-dump∂t--> create the MakeFile but don't execute it."
  72.     Exit 0
  73. End
  74.  
  75. # Unless we specified the -dump option the MakeFile
  76. # is generated in the MPW temp folder located inside
  77. # the MPW prefs folder.  If we did specify the -dump
  78. # option it is generated in the target's directory.
  79.  
  80. If {Dump} == 0
  81.     Set MakeFile "{TempFolder}tmp.make"
  82. Else
  83.     Set MakeFile "Prebuild.make"
  84. End
  85.  
  86. If {Progress}
  87.     Echo "Executing FWPreBuild for target(s): {Parameters}"
  88.     Echo "∂tSOM directory: ∂'{somDir}∂'"
  89.     Echo "∂tResource directory: ∂'{resDir}∂'"
  90. End
  91.  
  92. # Since we can specify multiple targets we will iterate through
  93. # them and attempt to invoke SOM, ODFrc, and Rez as needed for
  94. # each target.
  95.  
  96. For TargItem in {Parameters}
  97.  
  98.     # First see if they forgot the trailing colon on the target. path
  99.     # If so we add it for them.
  100.  
  101.     If {TargItem} =~ /≈:/
  102.         Set TargFldr "{TargItem}"
  103.     Else
  104.         Set TargFldr "{TargItem}:"
  105.     End
  106.  
  107.     # Make sure the target folder exists
  108.  
  109.     If ¬ `Exists "{TargFldr}"`
  110.         Echo "# Error: Can not find target folder ∂'{TargFldr}∂'!"
  111.         Directory "{StartDir}"
  112.         Exit 1
  113.     Else If {Progress}
  114.         Echo "# -------"
  115.         Echo "Looking in target folder ∂'{TargFldr}∂'"
  116.     End
  117.  
  118.     # Set directory to target folder
  119.  
  120.     Directory "{TargFldr}"
  121.  
  122.     # delete previous temp file if it exists.
  123.  
  124.     If `Exists {MakeFile}`
  125.         Delete "{MakeFile}"
  126.     End
  127.  
  128.     # Set the list of files to empty and clear flags.
  129.  
  130.     Set FList ""
  131.     Set GotIDL 0
  132.     Set GotFR 0
  133.     Set GotR 0
  134.  
  135.     # Next make sure the SOM IDL folder exists.
  136.  
  137.     If ¬ `Exists ":{somDir}:"`
  138.         Echo "# Warning: Can not find SOM IDL folder ∂'{TargFldr}{somDir}:∂'!"
  139.     Else 
  140.     
  141.         If {Progress}
  142.             Echo "Looking in theSOM IDL folder ∂'{TargFldr}{somDir}:∂'"
  143.         End
  144.         
  145.         # Look for .idl files in the SOM folder.
  146.  
  147.         Set LList "`Files :{somDir}:`"
  148.         If {Progress}
  149.             Echo "∂tScanning for .idl files in ∂':{somDir}:∂'"
  150.         End
  151.         For item in {LList}
  152.             If "{Item}" =~ /≈.idl/
  153.                 Set FList "{FList} :{somDir}:'{item}'"
  154.                 Set GotIDL 1
  155.             End
  156.         End
  157.     End
  158.  
  159.     # Now make sure the resource folder exists.
  160.  
  161.     If ¬ `Exists ":{resDir}:"`
  162.         Echo "# Warning: Can not find resource folder ∂'{TargFldr}{resDir}:∂'!"
  163.     Else 
  164.         If {Progress}
  165.             Echo "Looking in resource folder ∂'{TargFldr}{resDir}:∂'"
  166.         End
  167.     
  168.         # Look for .fr files in the resource folder.
  169.  
  170.         Set LList "`Files :{resDir}:`"
  171.         If {Progress}
  172.             Echo "∂tScanning for .fr files in ∂':{resDir}:∂'"
  173.         End
  174.         For item in {LList}
  175.             If "{Item}" =~ /≈.fr/
  176.                 Set FList "{FList} :{resDir}:'{item}'"
  177.                 Set GotFR 1
  178.             End
  179.         End
  180.  
  181.         # Look for .r files in the resource folder.
  182.  
  183.         Set LList "`Files :{resDir}:`"
  184.         If {Progress}
  185.             Echo "∂tScanning for .r files in ∂':{resDir}:∂'"
  186.         End
  187.         For item in {LList}
  188.             If "{Item}" =~ /≈.r/
  189.                 Set FList "{FList} :{resDir}:'{item}'"
  190.                 Set GotR 1
  191.             End
  192.         End
  193.     End
  194.     
  195.     # If we found any files while scanning, generate the
  196.     # makefile and execute it.
  197.  
  198.     If "{FList}" != ""
  199.     
  200.         # Copy the default rules to the makefile.
  201.         
  202.         If `Exists "{DefRul}"`
  203.             Catenate "{DefRul}" > "{MakeFile}"
  204.         Else
  205.             Echo "# Error: Can't find default make rules in file: ∂'{DefRul}∂'"
  206.             Directory "{StartDir}"
  207.             Exit 1
  208.         End
  209.     
  210.         # Emit the root dependency.
  211.         
  212.         Echo "∂nroot ƒ ∂∂"  >> "{MakeFile}"
  213.     
  214.         For Name in {FList}
  215.             If {Progress}
  216.                 Echo "∂tEmiting root depedency for {Name}"
  217.             End
  218.  
  219.             Echo "∂t{Name} ∂∂" >> "{MakeFile}"
  220.         End
  221.     
  222.         # Emit the real make dependencies.
  223.         
  224.         For Name in {FList}
  225.             If {Progress}
  226.                 Echo "∂tEmiting depedency for {Name}"
  227.             End
  228.  
  229.             Echo "∂n{Name} ƒ {Name}" >> "{MakeFile}"
  230.         End
  231.     
  232.         # We must edit the results slightly.
  233.     
  234.         Open -t "{MakeFile}"
  235.         Find •
  236.         If {GotIDL}
  237.             Replace /.idl ∂∂/ '.xh ∂' -c ∞
  238.         End
  239.         If {GotFR}
  240.             Replace /.fr ∂∂/ '.rsrc ∂' -c ∞
  241.         End
  242.         If {GotR}
  243.             Replace /.r ∂∂/ '.rsrc ∂' -c ∞
  244.         End
  245.         Replace \ ∂∂\ ' ' -c 1
  246.         If {GotIDL}
  247.             Replace /.idl ƒ/ '.xh ƒ' -c ∞
  248.         End
  249.         If {GotFR}
  250.             Replace /.fr ƒ/ '.rsrc ƒ' -c ∞
  251.         End
  252.         If {GotR}
  253.             Replace /.r ƒ/ '.rsrc ƒ' -c ∞
  254.         End
  255.         Close -y "{MakeFile}"
  256.     
  257.         # Execute the make unless we specified -dump.
  258.     
  259.         If {Dump} == 0
  260.  
  261.             If {Progress}
  262.                 Echo "Running Make for {MakeFile}"
  263.             End
  264.         
  265.             Echo "Set Exit 1" > "{TempFile}"
  266.             Make -f "{MakeFile}" >> "{TempFile}"
  267.             Execute "{TempFile}"
  268.             Delete "{TempFile}"
  269.         End
  270.     
  271.     Else
  272.         Echo "# Warning: No .idl, .fr, or .r files found!"
  273.     End
  274.     
  275.     # Set our directory back to where we were when we executed this script.
  276.     
  277.     Directory "{StartDir}"
  278. End
  279.  
  280. # Unless we specified the -dump option we delete our
  281. # temporary MakeFile.
  282.     
  283. If !{NoCleanup}
  284.     If `Exists "{MakeFile}"`
  285.         Delete "{MakeFile}"
  286.     End
  287. End
  288.  
  289.